package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.renren.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.ParkEntity;
import io.renren.modules.generator.service.ParkService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 车位管理
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-03-31 20:08:29
 */
@RestController
@RequestMapping("generator/park")
public class ParkController extends AbstractController {
    @Autowired
    private ParkService parkService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:park:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = parkService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:park:info")
    public R info(@PathVariable("id") Long id){
		ParkEntity park = parkService.getById(id);

        return R.ok().put("park", park);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:park:save")
    public R save(@RequestBody ParkEntity park){
        park.setCreateTime(new Date());
        park.setCreateUserId(getUserId());
		parkService.save(park);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:park:update")
    public R update(@RequestBody ParkEntity park){
		parkService.updateById(park);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:park:delete")
    public R delete(@RequestBody Long[] ids){
		parkService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
